package xkp.lesson5;

import java.util.function.Consumer;

public class TestLambda1 {
    public static void main(String[] args) {
        //匿名内部类
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("你好");
                System.out.println("你好");
                System.out.println("你好");
                System.out.println("你好");
            }
        };
        System.out.println("**********************************");
        //线程的run方法
        runnable.run();
        //Lambda表达式
        // public abstract void run();
        Runnable runnable1 = ()->{
            System.out.println("你好");
            System.out.println("你好");
            System.out.println("你好");
            System.out.println("你好");
        };
        System.out.println("**********************************");
        runnable1.run();

        //主要方法体有多行代码，则大括号不能省略
        Runnable runnable2 = ()-> System.out.println("你好");
        System.out.println("**********************************");
        runnable2.run();

        //有一个参数，没有返回值
        MyInterface1 myInterface = new MyInterface1() {
            @Override
            public void fun(String name) {
                System.out.println(name);
            }
        };
        myInterface.fun("张三");

        MyInterface1 myInterface1 = (dsfjafhdsjf)-> System.out.println(dsfjafhdsjf);
        myInterface1.fun("李四");

        System.out.println("****************************");


        MyInterface2 myInterface21 = new MyInterface2() {
            @Override
            public void fun(String name, Integer age) {
                System.out.println(name+":"+age);
            }
        };

        MyInterface2 myInterface22 = (name,age)-> System.out.println(name+":"+age);
        myInterface22.fun("张三",20);

        Consumer<Object> consumer = new Consumer<Object>() {
            @Override
            public void accept(Object o) {
                System.out.println(o);
            }
        };

      /*  Consumer<Object> consumer1 = (obj)->{
            System.out.println(obj);
            System.out.println(obj);
            System.out.println(obj);
            System.out.println(obj);

        };*/

        Consumer<Object> consumer1 = obj->System.out.println(obj);
        System.out.println("*************************************");

        MyInterface3 myInterface3 = new MyInterface3() {
            @Override
            public Integer sum(Integer num1, Integer num2) {
                Integer result = num1+num2;
                return result;
            }
        };
        Integer sum = myInterface3.sum(100,200);

        MyInterface3 myInterface31 = (num1,num2)->{
            Integer result = num1+num2;
            return result;
        };
        System.out.println(myInterface31.sum(200,300));
    }
}